package com.example.news.dao;

import com.example.news.entity.LoginTicket;
import org.apache.ibatis.annotations.*;

@Mapper
@Deprecated
// 改用redis优化后弃用
public interface LoginTicketMapper {

    // 简单sql，用注解的方法声明，不用写xml文件
    // 但不便阅读，写标签也不方便

    @Insert({
            "insert into login_ticket(user_id,ticket,status,expired) ",
            "values(#{userId},#{ticket},#{status},#{expired})"
    })  //会自动拼接成sql语句
    @Options(useGeneratedKeys = true, keyProperty = "id")   //自动生成主键注给id
    int insertLoginTicket(LoginTicket loginTicket);

    @Select({
            "select id,user_id,ticket,status,expired ",
            "from login_ticket where ticket=#{ticket}"
    })
    LoginTicket selectByTicket(String ticket);


    @Update({
            "update login_ticket set status=#{status} where ticket=#{ticket} ",
    })
//    @Update({
//            "<script>",
//            "update login_ticket set status=#{status} where ticket=#{ticket} ",
//            "<if test=\"ticket!=null\"> ",
//            "and 1=1 ",
//            "</if>",
//            "</script>"
//    })  //动态sql写法演示
    int updateStatus(String ticket, int status);

}
